require_relative 'device'

module Deviceify
  class Map
    @@_devices = {}

    def self.name(model_string)
      dev = self.device(model_string)
      return dev.name if dev
      model_string
    end
    def self.device(model_string)
      object = Deviceify::DEVICE_MAP[model_string]
      if object
        return Deviceify::Device.new(object)
      end
      nil
    end
    def self.devices
      return @@_devices if @@_devices.count > 0
      Deviceify::DEVICE_MAP.each do |key, val|
        @@_devices[key] = Deviceify::Device.new(val)
      end
      @@_devices
    end
  end

  DEVICE_MAP = {
    # Apple TVs
    "AppleTV3,1" => {
      name: "Apple TV",
      generation: "Apple TV 3G",
      models: %w[A1427],
      fcc_ids: %w[BCGA1427],
      sizes: %w[8GB]
    },
    "AppleTV3,2" => {
      name: "Apple TV",
      generation: "Apple TV 3G",
      models: %w[A2469],
      fcc_ids: %w[BCGA1469],
      sizes: %w[8GB]
    },
    # iPads
    "iPad1,1" => {
      name: "iPad",
      generation: "iPad 1G",
      models: %w[A1219 A1337],
      fcc_ids: %w[BCG‑E2381A BCG‑E2328A],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad2,1" => {
      name: "iPad 2",
      generation: "iPad 2",
      models: %w[A1395],
      fcc_ids: %w[BCGA1395],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad2,2" => {
      name: "iPad 2",
      generation: "iPad 2",
      models: %w[A1396],
      fcc_ids: %w[BCGA1396],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad2,3" => {
      name: "iPad 2",
      generation: "iPad 2",
      models: %w[A1397],
      fcc_ids: %w[BCGA1397],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad2,4" => {
      name: "iPad 2",
      generation: "iPad 2",
      models: %w[A1395],
      fcc_ids: %w[BCGA1395],
      sizes: %w[16GB]
    },
    "iPad3,1" => {
      name: "iPad 3",
      generation: "iPad 3",
      models: %w[A1416],
      fcc_ids: %w[BCGA1416],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad3,2" => {
      name: "iPad 3",
      generation: "iPad 3",
      models: %w[A1403],
      fcc_ids: %w[BCGA1403],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad3,3" => {
      name: "iPad 3",
      generation: "iPad 3",
      models: %w[A1430],
      fcc_ids: %w[BCGA1430],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad3,4" => {
      name: "iPad 4",
      generation: "iPad 4",
      models: %w[A1458],
      fcc_ids: %w[BCGA1458],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    "iPad3,5" => {
      name: "iPad 4",
      generation: "iPad 4",
      models: %w[A1459],
      fcc_ids: %w[BCGA1459],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    "iPad3,6" => {
      name: "iPad 4",
      generation: "iPad 4",
      models: %w[A1460],
      fcc_ids: %w[BCGA1460],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    "iPad4,1" => {
      name: "iPad Air",
      generation: "iPad Air",
      models: %w[A1474],
      fcc_ids: %w[BCGA1474],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    "iPad4,2" => {
      name: "iPad Air",
      generation: "iPad Air",
      models: %w[A1475],
      fcc_ids: %w[BCGA1475],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    # iPad Mini
    "iPad2,5" => {
      name: "iPad Mini",
      generation: "iPad Mini 1G",
      models: %w[A1432],
      fcc_ids: %w[BCGA1432],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad2,6" => {
      name: "iPad Mini",
      generation: "iPad Mini 1G",
      models: %w[A1454],
      fcc_ids: %w[BCGA1454],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad2,7" => {
      name: "iPad Mini",
      generation: "iPad Mini 1G",
      models: %w[A1455],
      fcc_ids: %w[BCGA1455],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPad4,4" => {
      name: "iPad Mini",
      generation: "iPad Mini 2G",
      models: %w[A1489],
      fcc_ids: %w[BCGA1489],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    "iPad4,5" => {
      name: "iPad Mini",
      generation: "iPad Mini 2G",
      models: %w[A1517],
      fcc_ids: %w[BCGA1490],
      sizes: %w[16GB 32GB 64GB 128GB]
    },
    # iPhone
    "iPhone1,1" => {
      name: "iPhone",
      generation: "iPhone 2G",
      models: %w[A1203],
      fcc_ids: %w[BCGA1203],
      sizes: %w[4GB 8GB 16GB]
    },
    "iPhone1,2" => {
      name: "iPhone 3G",
      generation: "iPhone 3G",
      models: %w[A1241 A1324],
      fcc_ids: %w[BCGA1241],
      sizes: %w[8GB 16GB]
    },
    "iPhone2,1" => {
      name: "iPhone 3GS",
      generation: "iPhone 3GS",
      models: %w[A1303 A1325],
      fcc_ids: %w[BCGA1303A BCGA1303B],
      sizes: %w[8GB 16GB 32GB]
    },
    "iPhone3,1" => {
      name: "iPhone 4",
      generation: "iPhone 4",
      models: %w[A1332],
      fcc_ids: %w[BCG‑E2380A BCG‑E2380B],
      sizes: %w[8GB 16GB 32GB]
    },
    "iPhone3,2" => {
      name: "iPhone 4",
      generation: "iPhone 4",
      models: %w[A1332],
      fcc_ids: %w[BCG‑E2380A BCG‑E2380B],
      sizes: %w[8GB]
    },
    "iPhone3,3" => {
      name: "iPhone 4",
      generation: "iPhone 4",
      models: %w[A1349],
      fcc_ids: %w[BCG‑E2422A BCG‑E2422B],
      sizes: %w[8GB 16GB 32GB]
    },
    "iPhone4,1" => {
      name: "iPhone 4S",
      generation: "iPhone 4S",
      models: %w[A1387 A1431],
      fcc_ids: %w[BCG‑E2430A],
      sizes: %w[8GB 16GB 32GB 64GB]
    },
    "iPhone5,1" => {
      name: "iPhone 5",
      generation: "iPhone 5",
      models: %w[A1428],
      fcc_ids: %w[BCG‑E2599A],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPhone5,2" => {
      name: "iPhone 5",
      generation: "iPhone 5",
      models: %w[A1429 A1442],
      fcc_ids: %w[BCG‑E2599A],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPhone5,3" => {
      name: "iPhone 5c",
      generation: "iPhone 5c",
      models: %w[A1456 A1532],
      fcc_ids: %w[BCG‑E2644A],
      sizes: %w[16GB 32GB]
    },
    "iPhone5,4" => {
      name: "iPhone 5c",
      generation: "iPhone 5c",
      models: %w[A1507 A1516 A1526 A1529],
      fcc_ids: %w[BCG‑E2694A BCG‑E2694B],
      sizes: %w[16GB 32GB]
    },
    "iPhone6,1" => {
      name: "iPhone 5s",
      generation: "iPhone 5s",
      models: %w[A1433 A1533],
      fcc_ids: %w[BCG‑E2642A],
      sizes: %w[16GB 32GB 64GB]
    },
    "iPhone6,2" => {
      name: "iPhone 5s",
      generation: "iPhone 5s",
      models: %w[A1457 A1518 A1528 A1530],
      fcc_ids: %w[BCG‑E2643A BCG‑E2643B],
      sizes: %w[16GB 32GB 64GB]
    },
    # iPod Touch
    "iPod1,1" => {
      name: "iPod Touch",
      generation: "iPod Touch 1G",
      models: %w[A1213],
      fcc_ids: %w[BCGA1213],
      sizes: %w[8GB 16GB 32GB]
    },
    "iPod2,1" => {
      name: "iPod Touch",
      generation: "iPod Touch 2G",
      models: %w[A1288],
      fcc_ids: %w[BCGA1288],
      sizes: %w[8GB 16GB 32GB]
    },
    "iPod3,1" => {
      name: "iPod Touch",
      generation: "iPod Touch 3G",
      models: %w[A1318],
      fcc_ids: %w[BCG‑2310],
      sizes: %w[32GB 64GB]
    },
    "iPod4,1" => {
      name: "iPod Touch",
      generation: "iPod Touch 4G",
      models: %w[A1367],
      fcc_ids: %w[BCG‑E2407],
      sizes: %w[8GB 16GB 32GB 64GB]
    },
    "iPod5,1" => {
      name: "iPod Touch",
      generation: "iPod Touch 5G",
      models: %w[A1421 A1509],
      fcc_ids: %w[BCG‑A1421],
      sizes: %w[16GB 32GB 64GB]
    },
  }
end
